package br.inf.solutions.apresentacoes.ssp.control;

import java.util.ArrayList;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.vexillum.model.IActivatedEntity;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.StealthWeapon;

@Service
@Scope("prototype")
public class StealthWeaponController extends SearchPersonController<StealthWeapon>{

	public StealthWeaponController() {
		super(StealthWeapon.class);
	}
	
	@SuppressWarnings("unchecked")
	public Return joinCautionWeapon() {		
		Return ret = new Return(true);
		ArrayList<StealthWeapon> sw = (ArrayList<StealthWeapon>) searchStealthPerson().getList();

		ret.setList(sw);
		return ret;
	}

	public Return searchStealthPerson() {
		Return retPerson = new Return(true);
		
		Person per = getEntity().getPerson();
		String sql = "FROM " + classEntity.getSimpleName() + " WHERE person.rg = '" + per.getRg() + "' AND active = true AND open = true";
		data.put("sql", sql);
		retPerson.concat(searchByHQL());
		return retPerson;
	}
	
	public Return listAllNotStealth() {		
		String sql = "FROM Weapon WHERE active = true AND stealth = false AND unity.id = " + getEntity().getPerson().getUnity().getId();;
		if(data.get("entity") == null || (((IActivatedEntity) data.get("entity")).getActive() == null) || !((IActivatedEntity) data.get("entity")).getActive()){
			sql = sql.replace(" WHERE active = true", "");
		}
		data.put("sql", sql);
		return super.searchByHQL();
	}
}